<?php
/** 
 * EGP Framework
 *
 * LICENSE
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author     Akon(番茄红了) <aultoale@gmail.com>
 * @copyright  Copyright (c) 2008 (http://www.tblog.com.cn)
 * @license    http://www.gnu.org/licenses/gpl.html     GPL 3
 * @version    v1.0.0 Beta @ 2008-10-16
 */

!defined('EGP_LIB_DIR') && die('Access Deny!');

/**
 * Html (View Helper)
 *
 * @package    helper
 * @author     Akon(番茄红了) <aultoale@gmail.com>
 * @copyright  Copyright (c) 2008 (http://www.tblog.com.cn)
 * @license    http://www.gnu.org/licenses/gpl.html     GPL 3
 */
class EGP_View_Helper_Html extends EGP_View_Helper_Abstract
{

    /**
     * 判断两值如果相等，则返回指定的信息
     *
     * @param  mixed  $target
     * @param  mixed  $source
     * @param  mixed  $echo
     * @return mixed
     */
    public function ifCurrent($target, $source, $echo = null) {
        empty($echo) && $echo = ' style="color:red;font-weight:bold"';
        return $target == $source ? $echo : null;
    }

    /**
     * 判断两值如果相等，则返回 HTML option 的 selected
     *
     * @param  mixed  $target
     * @param  mixed  $source
     * @return string
     */
    public function selected($target, $source) {
        return $this->ifCurrent($target, $source, ' selected="selected"');
    }

    /**
     * 判断两值如果相等，则返回 HTML checkbox/radio 的 checked
     *
     * @param  mixed  $target
     * @param  mixed  $source
     * @return string
     */
    public function checked($target, $source) {
        return $this->ifCurrent($target, $source, ' checked="checked"');
    }

}